<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>用户登录</title>
        <link rel="stylesheet" type="text/css" href="/bower_components/bootstrap/dist/css/bootstrap.css">
        <script type="text/javascript" src="//cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
        <script type="text/javascript" src="/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
	    <script type="text/javascript" src="/bower_components/kindeditor/kindeditor-min.js"></script>
	    <script type="text/javascript" src="/bower_components/kindeditor/lang/zh-CN.js"></script>
	    <script type="text/javascript" src="/bower_components/upload-jquery/jquery.upload.js"></script>
    <body>
	    <div class="container">
	        <div class="row">
	        	<div class="col-md-8 col-md-offset-2">
	        		<form action="/admin/addArticle"  enctype="multipart/form-data" method="POST">
	        			<div class="page-header">
				    		<h4><a href="/admin"><<返回 </a> 添加文章</h4>
				        </div>
				        <%if(error1!=""){%>
				        <div class="alert alert-danger alert-dismissible" role="alert">
						  	<p><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><%=error1%></p>
						</div>
				        <%}%>
	        			<div class="form-group">
	        				<label>文章标题</label>
	        				<input type="text" name="title" class="form-control" placeholder="请输入文章标题">
	        			</div>
	        			<div class="form-group">
	        				<label>分类id</label>
	        				<select name="cata_id" class="form-control">
	        				<option value="$">---请选择分类id---</option>
	        					<% for(var i =0; i<catalog.length;i++){ %>
	        					<option value="<%=catalog[i].id%>"><%=catalog[i].name%></option>
	        					<%}%>
	        				</select>
	        			</div>
	        			<%if(error3!=""){%>
				        <div class="alert alert-danger alert-dismissible" role="alert">
						  	<p><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><%=error3%></p>
						</div>
				        <%}%>
	        			<div class="form-group">
	        				<label>图片地址</label>
	        				<div class="row" >
	        					<div class="col-md-8">
		        					<img src="" id="image"  height="100">
		        				</div>
		        				<div class="col-md-4">
		        					<a class="btn btn-success" onclick="doUpload()">上传文件</a>
		        				</div>
		        			</div>
	        			</div>
	        			<%if(error4!=""){%>
				        <div class="alert alert-danger alert-dismissible" role="alert">
						  	<p><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><%=error4%></p>
						</div>
				        <%}%>
	        			<div class="form-group">
	        				<label>文章内容</label>
	        				<textarea type="text" name="content" class="form-control" placeholder="请输入文章内容"></textarea>
	        			</div>
	        			<%if(error2!=""){%>
				        <div class="alert alert-danger alert-dismissible" role="alert">
						  	<p><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><%=error2%></p>
						</div>
				        <%}%>
	        			<button type="submit" class="btn btn-success">提交</button>
	        		</form>
	        	</div>
	        </div>
        </div>
<script>
	KindEditor.ready(function(K) {
		editor = K.create('textarea[name=content]', {
		allowFileManager : true
	});
});
	setTimeout(function(){
		$(".alert").fadeOut(2000)
	},3000)


	function doUpload(){
		$.upload({
			// 上传地址
			url: '/admin/uploadFile', 
			// 文件域名字
			fileName: 'fileInput', 
			// 其他表单数据
			params: {},
			// 上传完成后, 返回json, text
			dataType: 'text',
			// 上传之前回调,return true表示可继续上传
			onSend: function() {
					return true;
			},
			// 上传之后回调
			onComplate: function(data) {
				$('#image').attr('src',"/"+data)
			}
		});
	}
</script>
    </body>
</html>
